<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no" />
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>待付款</title>
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/personal/order-dsh.css">
    <script src="../../js/jquery-2.2.3.min.js"></script>
    <script src="../../js/rem.js"></script>
    <script src="../../js/common.js"></script>
    <style>
        .cont-name2 p {
            display: inline-block !important;
            float: left;
        }

        .cont-logo img {
            width: 100%;
            float: left;
        }
        .f-s-btn{
            margin: 0 0.05rem;
        }
        .apply-goods{
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            position: fixed;
            z-index: 10000;
        }
        .applyContainer{
            height: 1.9rem;
            width: 3rem;
            background: #ffffff;
            margin: 0 auto;
            position: absolute;
            top: 50%;
            margin-top: -0.95rem;
            left: 50%;
            margin-left: -1.5rem;
            border-radius: 0.1rem;
        }
        .apply-number{
            height: 0.5rem;
            line-height: 0.5rem;
            color: #8E8E93;
            font-size: 0.14rem;
            text-align: right;
            padding: 0 0.2rem;
        }
        .apply-num{
            background-color: #ffffff;
            /* line-height: 0.5rem; */
            width: 0.3rem;
            color: #8E8E93;
            border: none;
            outline: none;
            /* border-bottom: 1px solid #000000; */
            text-align: right;
        }
        .canapply{
            width: 90%;
            margin: 0.2rem auto;
        }
        .apply-ul{
            width: 90%;
            margin: 0.1rem auto;
            position: relative;
            overflow: hidden;
        }
        .apply-ul li{
            text-align: center;
            width: 50%;
            float: left;
            height: 0.3rem;
            line-height: 0.3rem;
        }
        .apply-line{
            display:block; left: 50%;margin-left: -0.5px;background: #ccc; width:1px;
            top: 50%;
            margin-top: -0.1rem; height: 0.2rem; position:absolute;
        }
    </style>
</head>

<body style="background-color: #F5F5F5">
    <div class="apply-goods" style="display:none;">
        <div class="applyContainer">
            <p class="apply-number">请输入要提货数<input style="background: #ffffff;" class="apply-num" type="text">件</p>
            <div class="apply-num-con">

            </div>
            <ul class="apply-ul">
                <li class="apply-dis">取消</li>
                <span class="apply-line"></span>
                <li class="apply-shure" style="color: #EB4748;">确认提货</li>
            </ul>
        </div>
    </div>
    <div class="head" style="z-index:1003;">
        <!-- <a href="javascript:history.back(-1)"> -->
        <div class="h-left" onclick="javascript:history.go(-1)"></div>
        <!-- </a> -->
        <div class="h-middle">待付款</div>
        <div class="h-right"></div>
    </div>
    <div style="height: .44rem; background-color: #ffffff;"></div>
    <div class="container-ban">
        <div class="head-cont">
            <p class="h-c-p1">待付款</p>
            <!-- <p class="h-c-p2">自动收货时间：11天02时04分10秒</p> -->
        </div>
        <div class="head-address">
            <img src="../../img/head-address.png" class="h-a-img" alt="">
            <p class="h-a-p1">
                <span class="left-sp"></span>
                <span class="right-sp"></span>
            </p>
            <p class="h-a-p2"></p>
        </div>
        <div class="dianpu-title">
            <img src="../../img/g_dianpu.png" class="g_dianpu" alt="">
            <span class="d-name"></span>
            <img src="../../img/icon-right.png" class="g_iconright" alt="">
        </div>
        <div class="cont">
            <!-- <div class="cont-logo"></div>
            <p class="cont-name">上海万豪国际酒店观景大床房主宿</p>
            <p class="cont-name2">观景大床房</p>
            <p class="cont-name3">不含早 | 有窗户 | 宽带</p>
            <span class="cont-money">￥1999.00</span>
            <span class="cont-money2"><s>￥1999.00</s></span>
            <span class="cont-num">×1</span> -->
        </div>
        <p class="title-p1">
            <span class="t-p-left">商品总价</span>
            <span class="t-p-right"></span>
        </p>
        <!-- <p class="title-p2">
            <span class="t-p-left">运费(快递)</span>
            <span class="t-p-right">￥0.00</span>
        </p> -->
        <p class="title-p3">
            <span class="t-p-left" style="color: #262626;font-size: .14rem">订单总价</span>
            <span class="t-p-right" style="color: #262626;font-size: .14rem"></span>
        </p>
    </div>
    <div class="beizhu">
        备注：请轻拿轻放
    </div>
    <div class="cont-bottom">
        <!-- |<span class="redColor"
            onClick="copyUrl2()">复制</span> -->
        <p class="c-b-p1 orderNumber">订单编号：<span class="orderNum"> </span></p>
        <!-- <p class="c-b-p1 payType">支付方式：微信支付</p> -->
        <p class="c-b-p1 creatTime">创建时间：</p>
        <p class="c-b-p1 fkTime">付款时间：</p>
        <p class="c-b-p1 wuliu">物流公司： </p>
        <p class="c-b-p1 wuNumber">物流单号：</p>
    </div>
    <div class="foot-submit">
        <div class="f-s-btn sqth" onclick="pickGoods(this)" style="display:none;">申请提货</div>
        <!--<div class="f-s-btn qzf" onclick="pickGoods()">去支付</div>-->
        <!--<div class="f-s-btn qxdd" onclick="deleteOrder(this)">取消订单</div>-->
        <div class="f-s-btn sqkc" style="display:none;" onclick="Inventory(this)">申请库存</div>
    </div>
</body>
<script>
    // 申请提货
    function pickGoods() {
        $('.apply-goods').show();
    }
    // 申请库存
    function Inventory() {
        $('.apply-goods').show();
    }
    $('.apply-dis').click(() => {
        $('.apply-goods').hide();
    })
    // 页面渲染
    var theRequest = GetRequest();
    $.ajax({
        url: SURL + '/jfd/ordersGoods/getOrderData',
        data: {
            orderId: theRequest.orderId
        },
        type: 'get',
        dataType: 'json',
        success: res => {
            var orderDfk = res.goodsOrder;
            var orderDfk1 = res.orders;
            var orderSta = '';
            var os = orderDfk1.orderStatus;
            if (os == 2) {
                orderSta = "待收货"
                $('.wuliu').show();
                $('.wuNumber').show();
                $('.fkTime').show();
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                $('.wuliu').text('物流公司：' + orderDfk1.expressName);
                $('.wuNumber').text('物流单号：' + orderDfk1.expressNo);
                $('.fkTime').text('付款时间：' + orderDfk1.paymentTime)
                $('.foot-submit').hide()
            } else if (os == 1) {
                orderSta = "已发货"
                if (orderDfk1.orderType == 1) {

                } else {
                    $('.foot-submit').hide()
                }
                $('.wuliu').show();
                $('.wuNumber').show();
                $('.fkTime').show();
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                $('.wuliu').text('物流公司：' + orderDfk1.expressName);
                $('.wuNumber').text('物流单号：' + orderDfk1.expressNo);
                $('.fkTime').text('付款时间：' + orderDfk1.paymentTime)
            } else if (os == 5) {
                $('.wuliu').show();
                $('.wuNumber').show();
                $('.fkTime').show();
                orderSta = "已完成"
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                $('.wuliu').text('物流公司：' + orderDfk1.expressName);
                $('.wuNumber').text('物流单号：' + orderDfk1.expressNo);
                $('.fkTime').text('付款时间：' + orderDfk1.paymentTime)
                $('.foot-submit').hide();
            } else if (os == -2) {
                orderSta = "待付款"
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                $('.wuliu').hide();
                $('.wuNumber').hide();
                $('.fkTime').hide();
                // $('.wuliu').text('物流公司：' + '');
                // $('.wuNumber').text('物流单号：' +'');
                // $('.fkTime').text('付款时间：' + '')
                $('.foot-submit').hide();
            }else if (os == 0) {
                orderSta = "已付款"
                if (orderDfk1.orderType == 1) {

                } else {
                    $('.foot-submit').hide()
                }
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                // $('.wuliu').text('物流公司：' + '');
                $('.wuliu').hide();
                $('.wuNumber').hide();
                $('.fkTime').hide();
                // $('.wuNumber').text('物流单号：' + '');
                // $('.fkTime').text('付款时间：' + orderDfk.paymentTime)
                $('.foot-submit').hide()
            }else if (os == 2) {
                orderSta = "待发货"
                $('.orderNum').text(orderDfk1.orderNo);
                $('.creatTime').text('创建时间：' + orderDfk1.createTime);
                $('.wuliu').text('物流公司：' + orderDfk1.expressName);
                $('.wuNumber').text('物流单号：' +orderDfk1.expressNo);
                $('.fkTime').text('付款时间：' + orderDfk1.paymentTime)
                $('.foot-submit').hide();
            }
            var address1 = res.address;
            $('.h-middle').text(orderSta);
            $('.h-c-p1').text(orderSta);
            $('.left-sp').text('收货人:' + address1.userName);
            $('.right-sp').text(address1.userPhone);
            $('.h-a-p2').text(address1.userAddress);
            $('.d-name').text(orderDfk1.shopName);
            address1.remark == null ? $('.beizhu').text('备注：') : $('.beizhu').text(address1.remark);
            $('.orderNum').text(address1.orderNo);
            $('.title-p1').children('.t-p-right').text('￥' + orderDfk1.goodsMoney)
            $('.title-p3').children('.t-p-right').text('￥' + orderDfk1.goodsMoney)
            orderDfk.forEach(element=>{
                $('.cont').append(
                    `
                <li style="clear: both;">
                    <div class="cont-logo">
                        <img src="${element.goodsImg}">
                    </div>
                    <p class="cont-name">${element.goodsName}</p>
                    <span class="cont-money">￥${element.goodsPrice}</span>
                    <span class="cont-num">×${element.goodsNum}</span>
                </li>
            `
                )
            })

        }
    })

    // 取消订单
    function deleteOrder(e) {
        var orderId = theRequest.orderId;
        $.ajax({
            url: SURL + '/jfd/ordersGoods/updateOrderStatus',
            data: {
                orderId: orderId,
                orderStatus: -1
            },
            type: 'get',
            dataType: 'json',
            success: res => {
                // res.code==1?
                // console.log(res);
                if (res.code == 1) {
                    alert(res.msg);
                    window.location.href = 'myorder.html';
                }
            }
        })
    }
    // 申请提货
    function pickGoods(e) {
        $('.apply-num-con').html('');
        $('.apply-goods').show();
        // alert(Math.ceil(23*0.4));
        var dataId = $(e).attr('data-id');
        // $('.apply-shure').click(()=>{
        $.ajax({
            url: SURL + '/jfd/shopOrders/toApplyGoods',
            data: {
                type: 1,
                orderId: dataId
            },
            type: 'post',
            dataType: 'json',
            success: res => {
                // console.log(res);
                $('.apply-num-con').append(
                    `
                        <p style="width: 90%;margin: 0.1rem auto 0.1rem auto;height:1px;background:#E3E3E3;"></p>
                        <p class="canapply">您当前商品总件数为${res.data[0].goodsNum}件，可提货件数不得大于${res.data[0].maxSendNum}件也不能小于${res.data[0].minSendNum}件。</p>
                        <p style="width: 100%;margin: 0.1rem auto 0.1rem auto;height:1px;background:#E3E3E3;"></p>
                        `
                )
                $('.apply-shure').unbind('click').on("click", () => {
                    var applyNum = parseInt($('.apply-num').val());
                    if (applyNum > res.data[0].maxSendNum) {
                        alert('最大不能超过' + res.data[0].maxSendNum + '件')
                    } else if (applyNum < res.data[0].minSendNum) {
                        alert('最少不能少于' + res.data[0].minSendNum + '件')
                    } else if (!/^\\d+$/.test(applyNum) || isNaN(applyNum)) {
                        alert('商品数量只能为正整数并且不能为空');
                    } else {
                        var arr = [];
                        var ordersGoods = res.data[0].ordersGoodsId;
                        paramStrObj = {
                            ordersGoodsId: ordersGoods,
                            applyNum: applyNum
                        }
                        arr.push(paramStrObj);
                        var arr1 = JSON.stringify(arr)
                        var data = {
                            type: 1,
                            paramStr: arr1,
                            userId: localStorage.getItem('userId')
                        }
                        // console.log(applyNum)
                        // console.log(data).

                        $.ajax({
                            url: SURL + '/jfd/shopOrders/applyGoods',
                            data: data,
                            type: 'post',
                            dataType: 'json',
                            traditional: true,
                            success: res => {
                                alert(res.msg)
                                $('.apply-goods').hide();
                            }
                        })
                    }
                })
            }
            // })
        })
    }
    // 申请库存
    function Inventory(e) {
        $('.apply-num-con').html('');
        $('.apply-shure').text('放入库存')
        $('.apply-goods').show();
        // alert(Math.ceil(23*0.4));
        var dataId = $(e).attr('data-id');
        // $('.apply-shure').click(()=>{
        $.ajax({
            url: SURL + '/jfd/shopOrders/toApplyGoods',
            data: {
                type: 2,
                orderId: dataId
            },
            type: 'post',
            dataType: 'json',
            success: res => {
                // console.log(res);
                $('.apply-num-con').append(
                    `
                        <p style="width: 90%;margin: 0.1rem auto 0.1rem auto;height:1px;background:#E3E3E3;"></p>
                        <p class="canapply">您当前商品总件数为${res.data[0].goodsNum}件，可放入库存件数不得大于${res.data[0].maxStockNum}件也不能小于${res.data[0].minStockNum}件。</p>
                        <p style="width: 100%;margin: 0.1rem auto 0.1rem auto;height:1px;background:#E3E3E3;"></p>
                        `
                )
                $('.apply-shure').unbind('click').on("click", () => {
                    var applyNum = parseInt($('.apply-num').val());
                    if (applyNum > res.data[0].maxStockNum) {
                        alert('最大不能超过' + res.data[0].maxStockNum + '件')
                    } else if (applyNum < res.data[0].minStockNum) {
                        alert('最少不能少于' + res.data[0].minStockNum + '件')
                    } else if (!/^\\d+$/.test(applyNum) || isNaN(applyNum)) {
                        alert('商品数量只能为正整数并且不能为空');
                    } else {
                        var arr = [];
                        var ordersGoods = res.data[0].ordersGoodsId;
                        paramStrObj = {
                            ordersGoodsId: ordersGoods,
                            applyNum: applyNum
                        }
                        arr.push(paramStrObj);
                        var arr1 = JSON.stringify(arr)
                        var data = {
                            type: 2,
                            paramStr: arr1,
                            userId: localStorage.getItem('userId')
                        }
                        // console.log(data)
                        $.ajax({
                            url: SURL + '/jfd/shopOrders/applyGoods',
                            data: data,
                            type: 'post',
                            dataType: 'json',
                            traditional: true,
                            success: res => {
                                alert(res.msg)
                                $('.apply-goods').hide();
                            }
                        })
                    }
                })
            }
            // })
        })
    }
    $('.apply-dis').click(() => {
        $('.apply-goods').hide();
    })
    // 获取url地址
    function GetRequest() {
        //获取url中"?"符后的字串 
        var url = location.search;
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
</script>

</html>
